package com.tm.d3_exception;

import java.util.Scanner;

/**
 * 2024/6/2 Cjj 异常的处理方式：捕获异常，尝试修复
 */
public class ExceptiontTest4 {
    public static void main(String[] args) {
        while (true) {
            try {
                System.out.println(getMoney());
                break;
            } catch (java.lang.Exception e) {
                System.out.println("输入合法的数字");
            }
        }
    }
    public static double getMoney() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入合适的价格");
            double money = sc.nextDouble();
            if (money >= 0) {
                return money;
            } else {
                System.out.println("您输入的价格是不合适的");
            }
        }
    }
}
